﻿''' <summary>
''' 追加タイムスタンプ列属性
''' </summary>
''' <remarks></remarks>
<AttributeUsage(AttributeTargets.Property)>
Public Class CreateTimestampAttribute
    Inherits ColumnAttribute

    Shared ReadOnly COMMAND_TEXT As String = "CURRENT_TIMESTAMP"

#Region "Constructor"
    Public Sub New()
        Me.DirtyChecker = Function() False
        Me.IsLoadable = False
        Me.InsertColumnCommandCreater = AddressOf Me.CreateSaveColumnCommand
        Me.IsUpdatable = False
    End Sub

    Public Sub New(ByVal ColumnName As String)
        Me.New()
        Me.ColumnName = ColumnName
    End Sub
#End Region

    Private _commandText As String
    Public Property CommandText As String
        Get
            Return If(_commandText Is Nothing, COMMAND_TEXT, _commandText)
        End Get
        Set(value As String)
            _commandText = value
        End Set
    End Property

    Private Sub CreateSaveColumnCommand(instance As Object, sqlColumnBuilder As System.Action(Of String), sqlValueBuilder As System.Action(Of String), paramRegister As System.Func(Of Object, Type, String))
        sqlColumnBuilder.Invoke(Me.ColumnName)
        sqlValueBuilder.Invoke(Me.CommandText)
    End Sub

End Class
